package com.gongzhiyun.springboot3test.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.gongzhiyun.springboot3test.base.R;
import com.gongzhiyun.springboot3test.entity.TbFiles;
import com.gongzhiyun.springboot3test.service.TbFilesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/files")
@Tag(name = "文件上传下载")
public class FilesController {
    private final TbFilesService tbFilesService;

    @Operation(summary = "上传",description = "上传说明，需要登录")
    @PostMapping
    public R<TbFiles> upload(MultipartFile file){
        return tbFilesService.upload(file);
    }

    @Operation(summary = "下载",description = "下载说明，需要登录")
    @GetMapping("/{id}")
    public void download(@PathVariable("id") Integer id, HttpServletResponse response){
        tbFilesService.download(id, response);
    }
}
